home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / TURB_VIS / TCYBER25 / CYANI.ZIP / CYANI.PAS < prev    next >
Pascal/Delphi Source File  |  1994-10-20  |  37KB  |  1,428 lines

  1. {
  2. Turbo Vision CyberTools 2.5
  3. (C) 1994 Steve Goldsmith
  4. All Rights Reserved
  5.  
  6. CyberAnimate application plays Snip animation files, exports frames as
  7. 256 color PCX files, imports PCXs to a Snip file and views PCX files.
  8. Configuration stream compatible with CyberEdit 2.5.
  9.  
  10. Borland Pascal 7.x or Turbo Pascal 7.x and Turbo Vision 2.x are required to
  11. compile.
  12.  
  13. Set IDE directories to
  14.  
  15. \BP\UNITS;
  16. \BP\EXAMPLES\DOS\TVDEMO;
  17. \BP\EXAMPLES\DOS\TVFM;
  18.  
  19. These path names are BP 7.x defaults.  If you changed any of these then use
  20. the correct paths in Options|Directories...  See APP.INC for global compiler
  21. switches.
  22. }
  23.  
  24. program CyberAni;
  25.  
  26. {$I APP.INC}
  27. {$X+}
  28.  
  29. uses
  30.  
  31.   Dos,                           {bp units}
  32.   Memory, Drivers, Objects,      {tv units}
  33.   Views, Menus, Dialogs,
  34.   App, MsgBox, StdDlg, ColorSel,
  35.   Gadgets, HelpFile,             {tvdemo units}
  36.   ViewText,                      {tvfm units}
  37.   CAHelp, CACmds,                {cybertools units}
  38. {$IFDEF UseDLL}
  39.   CyberAPI,
  40. {$ELSE}
  41.   VGA,
  42. {$ENDIF}
  43.   VGACGFil, PCX, Snip,
  44.   SnipDlg, PCXSNP, CommDlgs, TVStr;
  45.  
  46. const
  47.  
  48.   appDocName  = 'CYBER.DOC';  {doc file name}
  49.   appCfgName  = 'CYEDIT.CFG'; {config stream file name}
  50.   appHelpName = 'CAHELP.HLP'; {help file name}
  51.   appExeName  = 'CYANI.EXE';  {name used to locate .exe for older dos}
  52.   appCfgHeaderLen = 10;       {header used by config stream}
  53.   appCfgHeader : string[appCfgHeaderLen] = 'CYBEREDIT'#26;
  54.   appViewDocBuf = 8192;       {buffer size for viewing doc file}
  55.  
  56.   appChrWidth8  = $01;        {set app options bit to 1 to select option}
  57.   appPageMode   = $02;
  58.   app8Colors    = $04;
  59.   app256Color   = $0100;      {app in 256 color mode}
  60.   appHelpInUse  = $8000;      {used by help system}
  61.   appScrOpts    = $07;        {mask of just screen options}
  62.  
  63.   appGraphWinX = 32;          {x = 32*8 = 256 pixels}
  64.   appGraphWinY = 8;           {y = 8*16 = 128 pixels}
  65.   appFadeInc   = 8;           {fade in/out increment}
  66.  
  67.   CSysColor = #$00#$00#$00;   {app palette additions for tv system stuff}
  68.   CSysPal   = #137#138#139;
  69.  
  70. type
  71.  
  72.   TCyberAni = object (TApplication)
  73.     FontTable1,
  74.     FontTable2,
  75.     FirstChr,
  76.     LastChr : byte;
  77.     AppOptions,
  78.     PageOfs,
  79.     DefChrHeight : word;
  80.     Page : pointer;
  81.     DefFont : vgaChrTablePtr;
  82.     DacPalette : vgaPalette;
  83.     ScrData : ScrOptsData;
  84.     Clock : PClockView;
  85.     Heap : PHeapView;
  86.     constructor Init;
  87.     destructor Done; virtual;
  88.     procedure SetCustomScreen;
  89.     procedure FlipPage;
  90.     procedure ClearDeskTop;
  91.     procedure Idle; virtual;
  92.     procedure AboutBox;
  93.     procedure LoadFontTable (ChrData : pointer;
  94.                              ChrTable, ChrHeight :byte;
  95.                              StartChr, NumChrs : word);
  96.     function SaveFontTable (ChrTable, ChrHeight :byte;
  97.                             StartChr, NumChrs : word) : vgaChrTablePtr;
  98.     procedure RestoreDesktop (F : PathStr);
  99.     procedure SaveDeskTop (F : PathStr);
  100.     procedure GetEvent (var Event : TEvent); virtual;
  101.     function GetPalette : PPalette; virtual;
  102.     procedure HandleEvent (var Event : TEvent); virtual;
  103.     procedure InitDeskTop; virtual;
  104.     procedure InitMenuBar; virtual;
  105.     procedure InitStatusLine; virtual;
  106.     procedure OutOfMemory; virtual;
  107.     procedure LoadDesktop (var S : TStream);
  108.     procedure StoreDesktop (var S : TStream);
  109.   end;
  110.  
  111. {
  112. Initilize TV app.
  113. }
  114.  
  115. constructor TCyberAni.Init;
  116.  
  117. var
  118.  
  119.   R :TRect;
  120.  
  121. begin
  122.   LowMemSize := 512;    {8192 byte safety pool}
  123.   inherited Init;
  124.   RegisterObjects;      {register stuff for stream access}
  125.   RegisterViews;
  126.   RegisterMenus;
  127.   RegisterDialogs;
  128.   RegisterApp;
  129.   RegisterHelpFile;
  130.  
  131.   GetExtent (R);   {gadgets included with tvdemo}
  132.   R.A.Y := R.B.Y-1;
  133.   R.B.X := R.B.X-1;
  134.   R.A.X := R.B.X-8;
  135.   Heap := New (PHeapView,Init(R));
  136.   Heap^.GrowMode := gfGrowAll;
  137.   Insert (Heap);
  138.  
  139.   GetExtent (R);
  140.   R.B.Y := R.A.Y+1;
  141.   R.B.X := R.B.X-1;
  142.   R.A.X := R.B.X-8;
  143.   Clock := New (PClockView,Init (R));
  144.   Insert (Clock);
  145.  
  146.   RestoreDesktop (appCfgName); {load config stream}
  147.   AboutBox
  148. end;
  149.  
  150. {
  151. Done TV app.
  152. }
  153.  
  154. destructor TCyberAni.Done;
  155.  
  156. begin
  157.   if DefFont <> nil then      {dispose default font}
  158.     FreeMem (DefFont,vgaMaxChrs*DefChrHeight);
  159.   FadeOutDAC (appFadeInc);    {fade to black}
  160.   SetVideoMode (StartUpMode); {this resets all the custom stuff with bios}
  161.   inherited Done
  162. end;
  163.  
  164. {
  165. Sets screen page if not not flipping, 8 or 16 color mode, 8 or 9 pixel width,
  166. font map, DAC palette and mouse mask.
  167. }
  168.  
  169. procedure TCyberAni.SetCustomScreen;
  170.  
  171. begin
  172.   HideMouse;
  173.   if AppOptions and appPageMode = 0 then
  174.     SetPage (vgaPageOfsLoc[0]); {screen page 0 for non page flipping displays}
  175.   if AppOptions and app8Colors = app8Colors then
  176.     SetAttrCont (vgaAttrCPEnable,$07)  {use 8 colors}
  177.   else
  178.     SetAttrCont (vgaAttrCPEnable,$0f); {use 16 colors}
  179.   if AppOptions and appChrWidth8 = appChrWidth8 then
  180.   begin
  181.     if IsChrWidth9 then
  182.       SetChrWidth8 {640 x 400 screen}
  183.   end
  184.   else
  185.   begin
  186.     if not IsChrWidth9 then
  187.       SetChrWidth9 {720 x 400 screen}
  188.   end;
  189.   FontMapSelect (vgaChrTableMap1[FontTable1],
  190.   vgaChrTableMap2[FontTable2]);    {select font tables}
  191.   SetDACBlock (@DacPalette,0,256); {set 256 color palette}
  192.   MouseTextMask ($ffff,$f700);     {set mouse mask for both fonts}
  193.   ShowMouse
  194. end;
  195.  
  196. {
  197. Copy screen page 0 to new non-visiable page and flip to new page.
  198. }
  199.  
  200. procedure TCyberAni.FlipPage;
  201.  
  202. begin
  203.   CopyScrMem (ScreenBuffer,Page,vgaScrSize25);
  204.   SetPage (PageOfs);
  205.   if PageOfs = vgaPageOfsLoc[1] then
  206.   begin
  207.     PageOfs := vgaPageOfsLoc[2];
  208.     Page := vgaPageLoc[2]
  209.   end
  210.   else
  211.   begin
  212.     PageOfs := vgaPageOfsLoc[1];
  213.     Page := vgaPageLoc[1]
  214.   end;
  215.   WaitVertSync {wait for vga vert sync before drawing anything}
  216. end;
  217.  
  218. {
  219. Remove all closeable windows from desk top.
  220. }
  221.  
  222. procedure TCyberAni.ClearDeskTop;
  223.  
  224. procedure CloseDlg (P : PView); far;
  225.  
  226. begin
  227.   Message (P,evCommand,cmClose,nil)
  228. end;
  229.  
  230. begin
  231.   Desktop^.ForEach (@CloseDlg)
  232. end;
  233.  
  234. {
  235. Handle app's idle time processing.
  236. }
  237.  
  238. procedure TCyberAni.Idle;
  239.  
  240. {return true if any view on desk top is tileable}
  241.  
  242. function IsTileable (P : PView) : boolean; far;
  243.  
  244. begin
  245.   IsTileable := (P^.Options and ofTileable <> 0) and
  246.   (P^.State and sfVisible <> 0)
  247. end;
  248.  
  249. begin
  250.   inherited Idle;
  251.   Clock^.Update; {update tvdemo gadgets}
  252.   Heap^.Update;
  253.   if Desktop^.Current <> nil then              {see if anything is}
  254.   begin                                        {on the desk top}
  255.     EnableCommands ([cmCloseAll]);
  256.     if Desktop^.FirstThat (@IsTileable) <> nil then {see if any tileable}
  257.       EnableCommands ([cmTile,cmCascade])           {windows are on the}
  258.     else                                            {desk top}
  259.       DisableCommands ([cmTile,cmCascade])
  260.   end
  261.   else
  262.     DisableCommands ([cmCloseAll,cmTile,cmCascade]);
  263.   if ((Desktop^.Current <> nil) and
  264.   (Desktop^.Current^.State and sfModal = sfModal)) or
  265.   (AppOptions and appHelpInUse = appHelpInUse) then    {see if modal dialog}
  266.     DisableCommands ([cmQuit])                         {is on the desk top}
  267.   else
  268.     EnableCommands ([cmQuit]);
  269.   if AppOptions and appPageMode = appPageMode then
  270.     FlipPage  {if page mode is enabled then flip page each idle cycle}
  271. end;
  272.  
  273. {
  274. Display info about app.
  275. }
  276.  
  277. procedure TCyberAni.AboutBox;
  278.  
  279. begin
  280.   HelpCtx := hcAbout;
  281.   MessageBox(
  282.     #3'Turbo Vision CyberTools 2.5'#13+
  283.     #3'(C) 1994 Steve Goldsmith'#13+
  284. {$IFDEF DPMI}
  285.   {$IFDEF UseDLL}
  286.     #3'CyberAnimate DPMI, DLL',
  287.   {$ELSE}
  288.     #3'CyberAnimate DPMI',
  289.   {$ENDIF}
  290. {$ELSE}
  291.     #3'CyberAnimate REAL',
  292. {$ENDIF}
  293.     nil, mfInformation or mfOKButton);
  294.   HelpCtx := hcNoContext
  295. end;
  296.  
  297. {
  298. Load font table from system RAM.
  299. }
  300.  
  301. procedure TCyberAni.LoadFontTable (ChrData : pointer;
  302.                                    ChrTable, ChrHeight :byte;
  303.                                    StartChr, NumChrs : word);
  304.  
  305. begin
  306.   HideMouse;
  307.   AccessFontMem;
  308.   SetRamTable (StartChr,NumChrs,ChrHeight,ChrData,vgaChrTableLoc[ChrTable]);
  309.   AccessScreenMem;
  310.   ShowMouse
  311. end;
  312.  
  313. {
  314. Save font table from video RAM.
  315. }
  316.  
  317. function TCyberAni.SaveFontTable (ChrTable, ChrHeight :byte;
  318.                                    StartChr, NumChrs : word) : vgaChrTablePtr;
  319.  
  320. begin
  321.   HideMouse;
  322.   AccessFontMem;
  323.   SaveFontTable :=
  324.   GetRamTable (StartChr,NumChrs,ChrHeight,vgaChrTableLoc [ChrTable]);
  325.   AccessScreenMem;
  326.   ShowMouse
  327. end;
  328.  
  329. {
  330. Restore desk top stream.
  331. }
  332.  
  333. procedure TCyberAni.RestoreDesktop (F : PathStr);
  334.  
  335. var
  336.  
  337.   I : byte;
  338.   S : PStream;
  339.   Signature : string[appCfgHeaderLen];
  340.  
  341. begin
  342.   S := New (PBufStream,Init (F,stOpenRead,1024));
  343.   if LowMemory then OutOfMemory
  344.   else
  345.     if S^.Status <> stOk then
  346.     begin
  347.       MessageBox (#3'Unable to open file.',nil,mfOkButton+mfError)
  348.     end
  349.     else
  350.     begin
  351.       Signature[0] := Char (appCfgHeaderLen);
  352.       S^.Read (Signature[1],appCfgHeaderLen);
  353.       if Signature = appCfgHeader then {see if signature is right}
  354.       begin
  355.         S^.Read (AppOptions,SizeOf (AppOptions)); {read data from stream}
  356.         S^.Read (FontTable1,SizeOf (FontTable1));
  357.         S^.Read (FontTable2,SizeOf (FontTable2));
  358.         S^.Read (FirstChr,SizeOf (FirstChr));
  359.         S^.Read (LastChr,SizeOf (LastChr));
  360.         S^.Read (DacPalette,SizeOf (DacPalette));
  361.  
  362.         if DefFont = nil then
  363.           DefFont := MemAlloc (DefChrHeight*vgaMaxChrs);
  364.         HideMouse; {no screen writes during font mem access}
  365.         AccessFontMem;
  366.         for I := 0 to 7 do
  367.         begin
  368.           S^.Read (DefFont^,DefChrHeight*vgaMaxChrs);
  369.           SetRamTable (0,vgaMaxChrs,DefChrHeight,DefFont,vgaChrTableLoc[I])
  370.         end;
  371.         AccessScreenMem;
  372.         ShowMouse;
  373.  
  374.         LoadDesktop (S^);
  375.         LoadIndexes (S^);
  376.         ShadowAttr := GetColor (137);   {tv shadow color}
  377.         SysColorAttr := (GetColor (138) shl 8) or
  378.         GetColor (138);                 {tv system error color}
  379.         ErrorAttr := GetColor (139);    {tv palette index error color}
  380.         Application^.ReDraw; {draw app with new config}
  381.         if DefFont <> nil then
  382.         begin
  383.           FreeMem (DefFont,DefChrHeight*vgaMaxChrs);
  384.           DefFont := SaveFontTable (FontTable1,DefChrHeight,0,vgaMaxChrs)
  385.         end;
  386.         SetCustomScreen;
  387.         if S^.Status <> stOk then
  388.           MessageBox (#3'Stream error.',nil,mfOkButton+mfError);
  389.       end
  390.       else
  391.         MessageBox (#3'Invalid configuration format.',nil,mfOkButton+mfError)
  392.     end;
  393.   Dispose (S,Done)
  394. end;
  395.  
  396. {
  397. Save desk top stream.
  398. }
  399.  
  400. procedure TCyberAni.SaveDesktop (F : PathStr);
  401.  
  402. var
  403.  
  404.   I : byte;
  405.   CfgFile : File;
  406.   S : PStream;
  407.   SFont : vgaChrTablePtr;
  408.  
  409. begin
  410.   S := New(PBufStream,Init (F,stCreate,1024));
  411.   if not LowMemory and (S^.Status = stOk) then
  412.   begin
  413.     S^.Write (appCfgHeader[1],appCfgHeaderLen); {write stream data}
  414.     S^.Write (AppOptions,SizeOf (AppOptions));
  415.     S^.Write (FontTable1,SizeOf (FontTable1));
  416.     S^.Write (FontTable2,SizeOf (FontTable2));
  417.     S^.Write (FirstChr,SizeOf (FirstChr));
  418.     S^.Write (LastChr,SizeOf (LastChr));
  419.     GetDACBlock (@DacPalette,0,256);
  420.     S^.Write(DacPalette,SizeOf (DacPalette));
  421.  
  422.     HideMouse; {no screen write during font mem access}
  423.     AccessFontMem;
  424.     for I := 0 to 7 do {save all 8 vga font tables}
  425.     begin
  426.       SFont := GetRamTable (0,vgaMaxChrs,DefChrHeight,vgaChrTableLoc[I]);
  427.       S^.Write (SFont^,DefChrHeight*vgaMaxChrs);
  428.       if SFont <> nil then
  429.         FreeMem (SFont,DefChrHeight*vgaMaxChrs)
  430.     end;
  431.     AccessScreenMem;
  432.     ShowMouse;
  433.  
  434.     StoreDesktop (S^);
  435.     StoreIndexes (S^);
  436.     if S^.Status <> stOk then
  437.     begin {if stream error then delete file}
  438.       MessageBox (#3'Could not create stream.',nil,mfOkButton+mfError);
  439.       Dispose (S,Done);
  440.       Assign (CfgFile,F);
  441.       {$I-} Erase (CfgFile) {$I+};
  442.       Exit
  443.     end
  444.   end;
  445.   Dispose (S,Done)
  446. end;
  447.  
  448. {
  449. Intercept cmHelp to display help even when views are in modal state.
  450. }
  451.  
  452. procedure TCyberAni.GetEvent (var Event : TEvent);
  453.  
  454. function CalcHelpName : PathStr;
  455.  
  456. var
  457.  
  458.   EXEName : PathStr;
  459.   Dir : DirStr;
  460.   Name : NameStr;
  461.   Ext : ExtStr;
  462.  
  463. begin
  464.   if Lo (DosVersion) >= 3 then
  465.     EXEName := ParamStr (0)
  466.   else
  467.     EXEName := FSearch (appExeName, GetEnv ('PATH'));
  468.   FSplit (EXEName, Dir, Name, Ext);
  469.   if Dir[Length (Dir)] = '\' then
  470.     Dec (Dir[0]);
  471.   CalcHelpName := FSearch (appHelpName, Dir);
  472. end;
  473.  
  474. var
  475.  
  476.   W : PWindow;
  477.   HFile : PHelpFile;
  478.   HelpStrm : PDosStream;
  479.  
  480. begin
  481.   inherited GetEvent (Event);
  482.   case Event.What of
  483.     evCommand:
  484.       if (Event.Command = cmHelp) and
  485.       (AppOptions and appHelpInUse = 0) and
  486.       (AppOptions and app256Color = 0) then
  487.       begin {process help command if not in use and not in 256 color mode}
  488.         AppOptions := AppOptions or appHelpInUse; {help's in use}
  489.         HelpStrm := New (PDosStream, Init (CalcHelpName, stOpenRead));
  490.         HFile := New (PHelpFile, Init (HelpStrm));
  491.         if HelpStrm^.Status <> stOk then
  492.         begin
  493.           MessageBox (#3'Could not open help file.', nil, mfError + mfOkButton);
  494.           Dispose (HFile, Done);
  495.         end
  496.         else
  497.         begin
  498.           W := New (PHelpWindow,Init (HFile, GetHelpCtx));
  499.           if ValidView (W) <> nil then
  500.           begin
  501.             DisableCommands ([cmHelp]);
  502.             ExecView (W);
  503.             Dispose (W, Done);
  504.             EnableCommands ([cmHelp])
  505.           end;
  506.           ClearEvent (Event)
  507.         end;
  508.         AppOptions := AppOptions and not appHelpInUse
  509.       end;
  510.     evMouseDown:
  511.       if Event.Buttons <> 1 then
  512.         Event.What := evNothing
  513.   end
  514. end;
  515.  
  516. {
  517. Get custom app palette.
  518. }
  519.  
  520. function TCyberAni.GetPalette: PPalette;
  521.  
  522. const
  523.  
  524.   CNewColor = CAppColor+CHelpColor+CCharColor+CSysColor;
  525.   CNewBlackWhite = CAppBlackWhite+CHelpBlackWhite+CCharColor+CSysColor;
  526.   CNewMonochrome = CAppMonochrome+CHelpMonochrome+CCharColor+CSysColor;
  527.   P: array[apColor..apMonochrome] of string[Length (CNewColor)] =
  528.   (CNewColor, CNewBlackWhite, CNewMonochrome);
  529.  
  530. begin {add additional entries to the normal application palettes}
  531.   GetPalette := @P[AppPalette];
  532. end;
  533.  
  534. {
  535. Process app events.
  536. }
  537.  
  538. procedure TCyberAni.HandleEvent (var Event: TEvent);
  539.  
  540. {
  541. Load DOC file.
  542. }
  543.  
  544. procedure ViewTextFile (FileName : PathStr);
  545.  
  546. var
  547.  
  548.   T : PTextWindow;
  549.   R : TRect;
  550.  
  551. begin
  552.   GetExtent (R);
  553.   R.Grow (-5,-4);
  554.   T := New(PTextWindow, Init(R, FileName));
  555.   T^.Options := T^.Options or ofCentered;
  556.   T^.Palette := wpGrayWindow;
  557.   T^.HelpCtx := hcViewDoc;
  558.   InsertWindow (T)
  559. end;
  560.  
  561. {
  562. Text mode graphics window for viewing 2 color PCX images and fonts.
  563. }
  564.  
  565. procedure GraphicsWin (T : string);
  566.  
  567. var
  568.  
  569.   P : PChrSetDlg;
  570.  
  571. function IsThere (P : PView) : Boolean; far;
  572.  
  573. begin {see if view is a chr set dialog}
  574.   IsThere := (TypeOf (P^) = TypeOf (TChrSetDlg))
  575. end;
  576.  
  577. begin
  578.   PView (P) := Desktop^.FirstThat (@IsThere);
  579.   if P <> nil then {if on screen then close}
  580.   begin
  581.     if PChrSetDlg (P)^.Title <> nil then
  582.       DisposeStr (PChrSetDlg (P)^.Title);
  583.     PChrSetDlg (P)^.Title := NewStr (T);
  584.     PChrSetDlg (P)^.Frame^.DrawView;
  585.     PChrSetDlg (P)^.MakeFirst;
  586.   end
  587.   else
  588.   begin
  589.     P := New(PChrSetDlg,Init (T,appGraphWinX,appGraphWinY));
  590.     P^.Options := P^.Options or ofCentered;
  591.     P^.HelpCtx := hcPCXWindow;
  592.     InsertWindow (P)
  593.   end
  594. end;
  595.  
  596. {
  597. Load CGF file and store in table.
  598. }
  599.  
  600. procedure LoadChrFile (F : PathStr; ChrTbl : byte);
  601.  
  602. var
  603.  
  604.   ChrFile : TChrGenFile;
  605.  
  606. begin
  607.   ChrFile.Init;
  608.   ChrFile.OpenRead (F);
  609.   if (ChrFile.IoError = 0) and
  610.   (ChrFile.Header.Height = DefChrHeight) then
  611.   begin
  612.     ChrFile.ReadChrTable;
  613.     LoadFontTable (
  614.     ChrFile.ChrTablePtr,ChrTbl,ChrFile.Header.Height,
  615.     ChrFile.Header.StartChr,ChrFile.Header.TotalChrs)
  616.   end
  617.   else
  618.     MessageBox (#3'Problem reading font file.',nil,mfOkButton+mfError);
  619.   ChrFile.FreeChrTable;
  620.   ChrFile.Done
  621. end;
  622.  
  623. {
  624. Tree window.
  625. }
  626.  
  627. procedure TreeWindow (T : string; FMask : PathStr; ACmd : word);
  628.  
  629. var
  630.  
  631.   W : PDirWindow;
  632.   Drive : PathStr;
  633.  
  634. begin
  635.   GetDir (0,Drive);
  636.   W := New (PDirWindow,Init (T,Drive,FMask,ACmd));
  637.   W^.HelpCtx := hcTreeWindow;
  638.   InsertWindow (W)
  639. end;
  640.  
  641. {
  642. Return focused file name from dir tree window.  If the extension param is not
  643. null then that extension is used.
  644. }
  645.  
  646. function TreeFileName (TW : PDirWindow; EStr : PathStr; ReadFlag : boolean) : PathStr;
  647.  
  648. var
  649.  
  650.   F : file;
  651.   FName : PathStr;
  652.  
  653. begin
  654.   FName := UpCaseStr (TW^.FocDirName+TW^.NameLine^.Data^);
  655.   if (EStr <> '') and (FName[byte (FName[0])] <> '\') then {force extension}
  656.     FName := AddExtStr (FName,EStr);
  657.   if ReadFlag then
  658.     TreeFileName := FName
  659.   else
  660.   begin
  661.     Assign (F,FName);
  662.     {$I-} Reset (F); {$I+}
  663.     if IoResult = 0 then {see if file exists before writes}
  664.     begin
  665.       {$I-} Close (F); {$I+}
  666.       if MessageBox (FName+' already exists.  Erase and continue?',
  667.       nil,mfConfirmation or mfYesNoCancel) = cmYes then
  668.         TreeFileName := FName
  669.       else
  670.         TreeFileName := ''
  671.     end
  672.     else
  673.       TreeFileName := FName {doesn't exist, so return name}
  674.   end
  675. end;
  676.  
  677. {
  678. New file list.
  679. }
  680.  
  681. procedure NewFileList;
  682.  
  683. var
  684.  
  685.   D : PStrListDlg;
  686.  
  687. begin
  688.   D := New (PStrListDlg,Init ('File List'));
  689.   D^.HelpCtx := hcFileList;
  690.   InsertWindow (D)
  691. end;
  692.  
  693. {
  694. Add file to file list.
  695. }
  696.  
  697. procedure AddFileToList (TW : PDirWindow);
  698.  
  699. var
  700.  
  701.   I : integer;
  702.   F : PathStr;
  703.   D : PStrListDlg;
  704.  
  705. function IsStrList (V : PView) : boolean; far;
  706.  
  707. begin
  708.   IsStrList :=  TypeOf (V^) = TypeOf (TStrListDlg)
  709. end;
  710.  
  711. begin
  712.   F := TreeFileName (TW,'',true);
  713.   if F <> '' then
  714.   begin
  715.     D := PStrListDlg (Desktop^.FirstThat (@IsStrList));
  716.     if D <> nil then
  717.       with D^.StrBox^ do
  718.       begin
  719.         if (not LowMemory) and
  720.         (not PStringCollection (List)^.Search (@F,I)) then
  721.         begin
  722.           List^.Insert (NewStr(F));       {add file name to list}
  723.           SetRange (List^.Count);         {set list's range}
  724.           FocusItem (List^.IndexOf (@F)); {focus inserted item}
  725.           DrawView                        {draw box}
  726.         end
  727.       end
  728.   end
  729. end;
  730.  
  731. {
  732. Return first file list in Z order.
  733. }
  734.  
  735. function GetStrListDlg : PStrListDlg;
  736.  
  737. function IsStrList (V : PView) : boolean; far;
  738.  
  739. begin
  740.   IsStrList :=  TypeOf (V^) = TypeOf (TStrListDlg)
  741. end;
  742.  
  743. begin
  744.   GetStrListDlg := PStrListDlg (Desktop^.FirstThat (@IsStrList))
  745. end;
  746.  
  747. {
  748. Find first file list in Z order and handle missing and empty lists by
  749. returning nil.
  750. }
  751.  
  752. function GetFileList : PStrListDlg;
  753.  
  754. var
  755.  
  756.   D : PStrListDlg;
  757.  
  758. begin
  759.   D := GetStrListDlg;
  760.   if D <> nil then
  761.   begin
  762.     if D^.StrBox^.List^.Count = 0 then
  763.     begin
  764.       MessageBox (#3'File list empty',nil,mfOkButton+mfError);
  765.       D^.Focus;
  766.       D := nil
  767.     end
  768.   end
  769.   else
  770.   begin
  771.     MessageBox (#3'No file list found on desk top',nil,mfOkButton+mfError);
  772.     NewFileList;
  773.     D := nil
  774.   end;
  775.   GetFileList := D
  776. end;
  777.  
  778. {
  779. Load CGF file.
  780. }
  781.  
  782. procedure LoadFontFile (TW : PDirWindow);
  783.  
  784. var
  785.  
  786.   F : PathStr;
  787.  
  788. begin
  789.   F := TreeFileName (TW,'CGF',true);
  790.   if F <> '' then
  791.     LoadChrFile (F,FontTable1)
  792. end;
  793.  
  794. {
  795. Decode and view 2 color PCX file up to 640 X 480.  Actual viewing area is
  796. 256 X 128.
  797. }
  798.  
  799. procedure LoadPCXFile2 (TW : PDirWindow);
  800.  
  801. var
  802.  
  803.   F : PathStr;
  804.   Decode : TPCXToChrTable;
  805.  
  806. begin
  807.   F := TreeFileName (TW,'PCX',true);
  808.   if F <> '' then
  809.   begin
  810.     HideMouse; {no screen writes during font mem access}
  811.     Decode.Init (F,appGraphWinX,appGraphWinY,
  812.     DefChrHeight,vgaChrTableLoc[FontTable2]);
  813.     if Decode.ReadError = 0 then
  814.     begin
  815.       GraphicsWin ('');
  816.       ShowMouse
  817.     end
  818.     else
  819.     begin
  820.       ShowMouse;
  821.       MessageBox (#3'Problem reading PCX file.',nil,mfOkButton+mfError)
  822.     end;
  823.     Decode.Done
  824.   end
  825. end;
  826.  
  827. {
  828. Decode and view 256 color PCX file up to 320 X 200.  Font 1 and 2 tables are
  829. preserved.  Fades are implemented to smooth mode changes.
  830. }
  831.  
  832. procedure LoadPCXFile256 (TW : PDirWindow);
  833.  
  834. var
  835.  
  836.   F : PathStr;
  837.   IX, IY : word;
  838.   SaveFont1,
  839.   SaveFont2 : vgaChrTablePtr;
  840.   TempPal   : vgaPalette;
  841.   PCXDecode : TDecodePCXFile256;
  842.  
  843. begin
  844.   F := TreeFileName (TW,'PCX',true);
  845.   if F <> '' then
  846.   begin
  847.     PCXDecode.Init (F); {read header and set up buffers}
  848.     if PCXDecode.ReadError = 0 then
  849.     begin
  850.       AppOptions := AppOptions or app256Color;
  851.       FillChar (TempPal,SizeOf (TempPal),0); {make all black palette}
  852.       SaveFont1 :=
  853.       SaveFontTable (FontTable1,DefChrHeight,0,vgaMaxChrs); {save current font 1}
  854.       SaveFont2 :=
  855.       SaveFontTable (FontTable2,DefChrHeight,0,vgaMaxChrs); {save current font 2}
  856.       PCXDecode.DecodeFile;         {decode pcx file into buffer}
  857.       PCXDecode.Palette256to64;     {convert 8 bit palette to dac 6 bit}
  858.       HideMouse;
  859.       FadeOutDAC (appFadeInc);      {fade to black}
  860.       BiosSetVideo ($13);           {set 320 x 200 x 256 color with bios}
  861.       SetDACBlock (@TempPal,0,256); {set all black palette}
  862.       for IY := 0 to PCXDecode.YSize-1 do {copy buffer to screen}
  863.         for IX := 0 to PCXDecode.XSize-1 do
  864.           vgaScreen256 (Ptr (SegA000,$0000)^)[IY,IX] :=
  865.           PCXDecode.DecodeBufPtr^[IY*PCXDecode.XSize+IX];
  866.       FadeInDAC (@PCXDecode.ReadPalette,appFadeInc); {fade in pcx palette}
  867.       TempPal := DacPalette;  {save current app palette}
  868.       FillChar (DacPalette,   {prepare app palette for mode switch}
  869.       SizeOf (DacPalette),0);
  870.       AppOptions := AppOptions and not appPageMode; {kill text page flipping}
  871.       MessageBox ('Viewing PCX...',nil,mfOkButton); {wait while viewing image}
  872.       FadeOutDAC (appFadeInc);     {fade to black}
  873.       SetVideoMode (StartUpMode);  {use bios to set text mode}
  874.       SetCustomScreen;             {set custom app screen}
  875.       Redraw;                      {draw desk top}
  876.       if SaveFont1 <> nil then     {restore font 1 and 2 tables and free mem}
  877.       begin
  878.         LoadFontTable (SaveFont1,FontTable1,DefChrHeight,0,vgaMaxChrs);
  879.         FreeMem (SaveFont1,DefChrHeight*vgaMaxChrs);
  880.       end;
  881.       if SaveFont2 <> nil then
  882.       begin
  883.         LoadFontTable (SaveFont2,FontTable2,DefChrHeight,0,vgaMaxChrs);
  884.         FreeMem (SaveFont2,DefChrHeight*vgaMaxChrs);
  885.       end;
  886.       DacPalette := TempPal;              {restore app palette}
  887.       FadeInDAC (@DacPalette,appFadeInc); {fade in app palette}
  888.       ShowMouse;
  889.       AppOptions := AppOptions and not app256Color
  890.     end
  891.     else {error decoding pcx}
  892.       MessageBox (#3'Problem reading PCX file.',nil,mfOkButton+mfError);
  893.     PCXDecode.Done
  894.   end
  895. end;
  896.  
  897. {
  898. Play 256 color Snip file.
  899. }
  900.  
  901. procedure LoadSnipFile256 (TW : PDirWindow);
  902.  
  903. var
  904.  
  905.   F : PathStr;
  906.   SaveFont1,
  907.   SaveFont2 : vgaChrTablePtr;
  908.   TempPal   : vgaPalette;
  909.   D : PSnipDialog;
  910.  
  911. begin
  912.   F := TreeFileName (TW,'SNP',true);
  913.   if F <> '' then
  914.   begin
  915.     D := New (PSnipDialog, Init (F));
  916.     if D^.Snip.ReadError = snpNoError then
  917.     begin
  918.       AppOptions := AppOptions or app256Color;
  919.       FillChar (TempPal,SizeOf (TempPal),0); {make all black palette}
  920.       SaveFont1 :=
  921.       SaveFontTable (FontTable1,DefChrHeight,0,vgaMaxChrs); {save current font 1}
  922.       SaveFont2 :=
  923.       SaveFontTable (FontTable2,DefChrHeight,0,vgaMaxChrs); {save current font 2}
  924.       HideMouse;
  925.       TempPal := DacPalette;  {save current app palette}
  926.       FillChar (DacPalette,   {prepare app palette for mode switch}
  927.       SizeOf (DacPalette),0);
  928.       AppOptions := AppOptions and not appPageMode; {kill text page flipping}
  929.       D^.Snip.ReadPal256 (D^.Snip.PalPtr);
  930.       D^.Snip.ReadFrameTable;
  931.       FadeOutDAC (appFadeInc);      {fade to black}
  932.       BiosSetVideo ($13);           {set 320 x 200 x 256 color with bios}
  933.       SetDACBlock (@TempPal,0,256); {set all black palette}
  934.       D^.PlayerInfo;
  935.       D^.Step;                      {load first frame}
  936.       FadeInDAC (D^.Snip.PalPtr,appFadeInc); {fade in frame}
  937.       ExecuteDialog (D,nil);
  938.       FadeOutDAC (appFadeInc);     {fade to black}
  939.       SetVideoMode (StartUpMode);  {use bios to set text mode}
  940.       SetCustomScreen;             {set custom app screen}
  941.       Redraw;                      {draw desk top}
  942.       if SaveFont1 <> nil then     {restore font 1 and 2 tables and free mem}
  943.       begin
  944.         LoadFontTable (SaveFont1,FontTable1,DefChrHeight,0,vgaMaxChrs);
  945.         FreeMem (SaveFont1,DefChrHeight*vgaMaxChrs);
  946.       end;
  947.       if SaveFont2 <> nil then
  948.       begin
  949.         LoadFontTable (SaveFont2,FontTable2,DefChrHeight,0,vgaMaxChrs);
  950.         FreeMem (SaveFont2,DefChrHeight*vgaMaxChrs);
  951.       end;
  952.       DacPalette := TempPal;              {restore app palette}
  953.       FadeInDAC (@DacPalette,appFadeInc); {fade in app palette}
  954.       ShowMouse;
  955.       AppOptions := AppOptions and not app256Color
  956.     end
  957.     else
  958.     begin
  959.       Dispose (D,Done);
  960.       MessageBox (#3'Problem reading Snip file.',nil,mfOkButton+mfError)
  961.     end
  962.   end
  963. end;
  964.  
  965. {
  966. Make Snip file from 256 color PCX files in DOS search order.
  967. }
  968.  
  969. procedure MakeSNPFile;
  970.  
  971. var
  972.  
  973.   D : PStrListDlg;
  974.   SNP : PPCXSNP;
  975.  
  976. begin
  977.   D := GetFileList;
  978.   if D <> nil then
  979.   begin
  980.     SNP := New (PPCXSNP,Init (PStringCollection (D^.StrBox^.List)));
  981.     SNP^.HelpCtx := hcMakeSnipDialog;
  982.     ExecuteDialog (SNP,nil)
  983.   end
  984. end;
  985.  
  986. {
  987. Change directory.
  988. }
  989.  
  990. procedure ChangeDir;
  991.  
  992. var
  993.  
  994.   D: PChDirDialog;
  995.  
  996. begin
  997.   D := New (PChDirDialog,Init (cdNormal,101));
  998.   D^.HelpCtx := hcChDirDialog;
  999.   ExecuteDialog (D,nil)
  1000. end;
  1001.  
  1002. {
  1003. Restore default font loaded by config.
  1004. }
  1005.  
  1006. procedure RestoreDefFont;
  1007.  
  1008. begin
  1009.   if (DefFont <> nil) and
  1010.   (DefChrHeight = BiosGetChrHeight) then
  1011.     LoadFontTable (DefFont,FontTable1,DefChrHeight,0,vgaMaxChrs)
  1012. end;
  1013.  
  1014. {
  1015. Set custom screen options.
  1016. }
  1017.  
  1018. procedure ScreenOptions;
  1019.  
  1020. var
  1021.  
  1022.   D : PScrOptsDlg;
  1023.  
  1024. begin
  1025.   with ScrData do
  1026.   begin
  1027.     SMode := AppOptions and appScrOpts; {use only screen options}
  1028.     FontMapVal (GetSeqCont (vgaSeqChrMapSel),byte (FntTbl1),byte (FntTbl2));
  1029.     FChr := IntToStr (FirstChr);
  1030.     LChr := IntToStr (LastChr);
  1031.     D := New (PScrOptsDlg,Init);
  1032.     D^.Options := D^.Options or ofCentered;
  1033.     D^.HelpCtx := hcScreenDialog;
  1034.     if ExecuteDialog (D,@ScrData) <> cmCancel then
  1035.     begin
  1036.       AppOptions := (AppOptions and not appScrOpts)
  1037.       or SMode; {clear all scr opts bits and set bits returned from dialog}
  1038.       FontTable1 := FntTbl1;
  1039.       FontTable2 := FntTbl2;
  1040.       FirstChr := StrToInt (FChr);
  1041.       LastChr := StrToInt (LChr);
  1042.       SetCustomScreen {set screen with new settings}
  1043.     end
  1044.   end
  1045. end;
  1046.  
  1047. {
  1048. Set custom TV color palette.
  1049. }
  1050.  
  1051. procedure Colors;
  1052.  
  1053. {custom color items}
  1054. function DlgColorItems (Palette: Word; const Next: PColorItem) : PColorItem;
  1055.  
  1056. const
  1057.  
  1058.   COffset : array[dpBlueDialog..dpGrayDialog] of Byte = (64, 96, 32);
  1059.  
  1060. var
  1061.  
  1062.   Offset : Byte;
  1063.  
  1064. begin
  1065.   Offset := COffset[Palette];
  1066.   DlgColorItems :=
  1067.     ColorItem ('Frame passive',     Offset,
  1068.     ColorItem ('Frame active',      Offset + 1,
  1069.     ColorItem ('Frame icons',       Offset + 2,
  1070.     ColorItem ('Scroll bar page',   Offset + 3,
  1071.     ColorItem ('Scroll bar icons',  Offset + 4,
  1072.     ColorItem ('Static text',       Offset + 5,
  1073.  
  1074.     ColorItem ('Label normal',      Offset + 6,
  1075.     ColorItem ('Label selected',    Offset + 7,
  1076.     ColorItem ('Label shortcut',    Offset + 8,
  1077.  
  1078.     ColorItem ('Button normal',     Offset + 9,
  1079.     ColorItem ('Button default',    Offset + 10,
  1080.     ColorItem ('Button selected',   Offset + 11,
  1081.     ColorItem ('Button disabled',   Offset + 12,
  1082.     ColorItem ('Button shortcut',   Offset + 13,
  1083.     ColorItem ('Button shadow',     Offset + 14,
  1084.  
  1085.     ColorItem ('Cluster normal',    Offset + 15,
  1086.     ColorItem ('Cluster selected',  Offset + 16,
  1087.     ColorItem ('Cluster shortcut',  Offset + 17,
  1088.  
  1089.     ColorItem ('Input normal',      Offset + 18,
  1090.     ColorItem ('Input selected',    Offset + 19,
  1091.     ColorItem ('Input arrow',       Offset + 20,
  1092.  
  1093.     ColorItem ('History button',    Offset + 21,
  1094.     ColorItem ('History sides',     Offset + 22,
  1095.     ColorItem ('History bar page',  Offset + 23,
  1096.     ColorItem ('History bar icons', Offset + 24,
  1097.  
  1098.     ColorItem ('List normal',       Offset + 25,
  1099.     ColorItem ('List focused',      Offset + 26,
  1100.     ColorItem ('List selected',     Offset + 27,
  1101.     ColorItem ('List divider',      Offset + 28,
  1102.  
  1103.     ColorItem('Information pane',  Offset + 29,
  1104.     Next))))))))))))))))))))))))))))));
  1105. end;
  1106.  
  1107. function HelpColorItems(const Next: PColorItem): PColorItem;
  1108.  
  1109. begin
  1110.   HelpColorItems :=
  1111.     ColorItem ('Frame passive',     128,
  1112.     ColorItem ('Frame active',      129,
  1113.     ColorItem ('Frame icons',       130,
  1114.     ColorItem ('Scroll bar page',   131,
  1115.     ColorItem ('Scroll bar icons',  132,
  1116.     ColorItem ('Normal text',       133,
  1117.     ColorItem ('Key word',          134,
  1118.     ColorItem ('Select key word',   135,
  1119.     Next))))))))
  1120. end;
  1121.  
  1122. function CharColorItems (const Next: PColorItem) : PColorItem;
  1123.  
  1124. begin
  1125.   CharColorItems :=
  1126.     ColorItem ('2 color PCX', 136,
  1127.     Next)
  1128. end;
  1129.  
  1130. function SysColorItems (const Next: PColorItem) : PColorItem;
  1131.  
  1132. begin
  1133.   SysColorItems :=
  1134.     ColorItem ('Shadow',       137,
  1135.     ColorItem ('System error', 138,
  1136.     ColorItem ('Index error',  139,
  1137.     Next)))
  1138. end;
  1139.  
  1140. var
  1141.  
  1142.   D : PColorDialog;
  1143.  
  1144. begin
  1145.   D := New (PColorDialog,Init ('',
  1146.   ColorGroup ('Desktop',     DesktopColorItems(nil),
  1147.   ColorGroup ('Menus',       MenuColorItems(nil),
  1148.   ColorGroup ('Gray Windows',WindowColorItems(wpGrayWindow,nil),
  1149.   ColorGroup ('Blue Windows',WindowColorItems(wpBlueWindow,nil),
  1150.   ColorGroup ('Cyan Windows',WindowColorItems(wpCyanWindow,nil),
  1151.   ColorGroup ('Gray Dialogs',DlgColorItems(dpGrayDialog,nil),
  1152.   ColorGroup ('Blue Dialogs',DlgColorItems(dpBlueDialog,nil),
  1153.   ColorGroup ('Cyan Dialogs',DlgColorItems(dpCyanDialog,nil),
  1154.   ColorGroup ('Help',        HelpColorItems(nil),
  1155.   ColorGroup ('PCX',  CharColorItems(nil),
  1156.   ColorGroup ('System',      SysColorItems(nil),
  1157.   nil)))))))))))));
  1158.   D^.HelpCtx := hcColorDialog;
  1159.   if ExecuteDialog (D,Application^.GetPalette) <> cmCancel then
  1160.   begin
  1161.     DoneMemory; {dispose all group buffers}
  1162.     ReDraw;     {redraw application with new palette}
  1163.     ShadowAttr := GetColor (137);   {tv shadow color}
  1164.     SysColorAttr := (GetColor (138) shl 8) or
  1165.     GetColor (138);                 {tv system error color}
  1166.     ErrorAttr := GetColor (139)     {tv palette index error color}
  1167.   end
  1168. end;
  1169.  
  1170. {
  1171. Adjust 16 text colors at DAC level.
  1172. }
  1173.  
  1174. procedure AdjustPalette;
  1175.  
  1176. var
  1177.  
  1178.   D : PPalDlg;
  1179.  
  1180. begin
  1181.   D := New (PPalDlg,Init);
  1182.   D^.Options := D^.Options or ofCentered;
  1183.   D^.HelpCtx := hcPaletteDialog;
  1184.   if ExecuteDialog (D,nil) <> cmCancel then
  1185.     GetDACBlock (@DacPalette,0,256)
  1186. end;
  1187.  
  1188. {
  1189. Load .CFG file.
  1190. }
  1191.  
  1192. procedure LoadConfigFile (TW : PDirWindow);
  1193.  
  1194. var
  1195.  
  1196.   F : PathStr;
  1197.  
  1198. begin
  1199.   F := TreeFileName (TW,'CFG',true);
  1200.   if F <> '' then
  1201.     RestoreDeskTop (F)
  1202. end;
  1203.  
  1204. {
  1205. Save .CFG file.
  1206. }
  1207.  
  1208. procedure SaveConfigFile (TW : PDirWindow);
  1209.  
  1210. var
  1211.  
  1212.   F : PathStr;
  1213.  
  1214. begin
  1215.   F := TreeFileName (TW,'CFG',false);
  1216.   if F <> '' then
  1217.     SaveDeskTop (F)
  1218. end;
  1219.  
  1220. {
  1221. Force all oftileable windows to top.
  1222. }
  1223. procedure TileableOnTop (P : PView); far;
  1224.  
  1225. begin
  1226.   if (P^.Options and ofTileable = ofTileable) then
  1227.     P^.MakeFirst
  1228. end;
  1229.  
  1230. begin
  1231.   if (Event.What = evCommand) and
  1232.   ((Event.Command = cmCascade) or
  1233.   (Event.Command = cmTile)) then {seperate oftileable windows from nontileable ones}
  1234.     Desktop^.ForEach (@TileableOnTop);
  1235.   inherited HandleEvent (Event);
  1236.   case Event.What of
  1237.     evCommand:
  1238.       begin
  1239.         case Event.Command of {process commands}
  1240.           cmLoadFont    : TreeWindow ('Load Font File','*.CGF',cmLoadFont);
  1241.           cmLoadPCX2    : TreeWindow ('Load 2 Color PCX File','*.PCX',cmLoadPCX2);
  1242.           cmLoadPCX256  : TreeWindow ('Load 256 Color PCX File','*.PCX',cmLoadPCX256);
  1243.           cmSaveConfig  : TreeWindow ('Save Config Stream','*.CFG',cmSaveConfig);
  1244.           cmLoadConfig  : TreeWindow ('Load Config Stream','*.CFG',cmLoadConfig);
  1245.           cmPlaySnip    : TreeWindow ('Play 256 Color Snip','*.SNP',cmPlaySnip);
  1246.           cmFileBrowse  : TreeWindow ('File List Builder','*.PCX',cmAddFile);
  1247.           cmViewDoc     : ViewTextFile (appDocName);
  1248.           cmAbout       : AboutBox;
  1249.           cmMakeSnip    : MakeSNPFile;
  1250.           cmNewFileList : NewFileList;
  1251.           cmDirChange   : ChangeDir;
  1252.           cmCloseAll    : ClearDeskTop;
  1253.           cmRestoreDef  : RestoreDefFont;
  1254.           cmScreenOpts  : ScreenOptions;
  1255.           cmColors      : Colors;
  1256.           cmAdjPal      : AdjustPalette;
  1257.         else
  1258.           Exit
  1259.         end;
  1260.       end;
  1261.     evBroadcast :
  1262.     begin
  1263.       case Event.Command of {process broadcasts}
  1264.         cmLoadPCX2    : LoadPCXFile2 (PDirWindow (Event.InfoPtr));
  1265.         cmLoadPCX256  : LoadPCXFile256 (PDirWindow (Event.InfoPtr));
  1266.         cmSaveConfig  : SaveConfigFile (PDirWindow (Event.InfoPtr));
  1267.         cmLoadConfig  : LoadConfigFile (PDirWindow (Event.InfoPtr));
  1268.         cmPlaySnip    : LoadSnipFile256 (PDirWindow (Event.InfoPtr));
  1269.         cmAddFile     : AddFileToList (PDirWindow (Event.InfoPtr))
  1270.       end
  1271.     end
  1272.   end
  1273. end;
  1274.  
  1275. {
  1276. Assign desk top pattern char, page locations, set default char height from
  1277. bios and save current DAC palette.
  1278. }
  1279.  
  1280. procedure TCyberAni.InitDeskTop;
  1281.  
  1282. begin
  1283.   SetScreenMode (smCO80);              {make sure 80x25 active}
  1284.   inherited InitDeskTop;
  1285.   DeskTop^.Background^.Pattern := '▒'; {new wall paper}
  1286.   Page := vgaPageLoc[1];
  1287.   PageOfs := vgaPageOfsLoc[1];
  1288.   DefChrHeight := BiosGetChrHeight;
  1289.   GetDACBlock (@DacPalette,0,256)      {save current vga palette}
  1290. end;
  1291.  
  1292. {
  1293. Menu.
  1294. }
  1295.  
  1296. procedure TCyberAni.InitMenuBar;
  1297.  
  1298. var
  1299.  
  1300.   R : TRect;
  1301.  
  1302. begin
  1303.   GetExtent (R);
  1304.   R.B.Y := R.A.Y+1;
  1305.   MenuBar := New (PMenuBar,Init (R,NewMenu (
  1306.     NewSubMenu ('~F~ile',hcFile,NewMenu (
  1307.     NewSubMenu ('~L~oad',hcLoadFile,NewMenu (
  1308.       NewItem ('~F~ont...','F3',kbF3,cmLoadFont,hcLoadFile,
  1309.       NewItem ('~P~CX 2 color...','Shift+F3',kbShiftF3,cmLoadPCX2,hcLoadFile,
  1310.       NewItem ('PCX ~2~56 color...','',kbNoKey,cmLoadPCX256,hcLoadFile,
  1311.       NewItem ('~C~onfig...','Ctrl+F3',kbCtrlF3,cmLoadConfig,hcLoadFile,
  1312.       nil))))),
  1313.       NewItem ('~S~ave config...','Ctrl+F2',kbCtrlF2,cmSaveConfig,hcSaveFile,
  1314.       NewItem ('~P~lay Snip...','',kbNoKey,cmPlaySnip,hcPlaySnip,
  1315.       NewItem ('~M~ake Snip...','',kbNoKey,cmMakeSnip,hcMakeSnip,
  1316.       NewLine (
  1317.       NewItem ('~N~ew file list','',kbNoKey,cmNewFileList,hcNewFileList,
  1318.       NewItem ('~F~ile list builder','',kbNoKey,cmFileBrowse,hcFileListBuild,
  1319.       NewItem ('~C~hange dir...','',kbNoKey,cmDirChange,hcChangeDir,
  1320.       NewItem ('~V~iew doc','',kbNoKey,cmViewDoc,hcViewDoc,
  1321.       NewItem ('~A~bout','',kbNoKey,cmAbout,hcAbout,
  1322.       NewLine (
  1323.       NewItem ('E~x~it','Alt+X',kbAltX,cmQuit,hcExit,
  1324.       nil))))))))))))),
  1325.     NewSubMenu('~W~indow',hcWindows,NewMenu(
  1326.       StdWindowMenuItems(nil)),
  1327.     NewSubMenu ('~O~ptions',hcOptions,NewMenu (
  1328.       NewItem ('~S~creen...','',kbNoKey,cmScreenOpts,hcScreen,
  1329.       NewItem ('~C~olors...','',kbNoKey,cmColors,hcOColors,
  1330.       NewItem ('~A~djust palette...','',kbNoKey,cmAdjPal,hcAdjustPalette,
  1331.       NewItem ('~D~efault font','F4',kbNoKey,cmRestoreDef,hcDefaultFont,
  1332.       nil))))),nil))))))
  1333. end;
  1334.  
  1335. {
  1336. Status line.
  1337. }
  1338.  
  1339. procedure TCyberAni.InitStatusLine;
  1340.  
  1341. var
  1342.  
  1343.   R : TRect;
  1344.  
  1345. begin
  1346.   GetExtent (R);
  1347.   R.A.Y := R.B.Y-1;
  1348.   StatusLine := New (PStatusLine,Init(R,
  1349.     NewStatusDef (0,$FFFF,
  1350.       NewStatusKey ('~F1~ Help', kbF1, cmHelp,
  1351.       NewStatusKey ('~Alt+F3~ Close',kbAltF3,cmClose,
  1352.       NewStatusKey ('~Alt+X~ Exit',kbAltX,cmQuit,
  1353.       NewStatusKey ('',kbF4,cmRestoreDef,
  1354.       NewStatusKey ('',kbF3,cmLoadFont,
  1355.       NewStatusKey ('',kbShiftF3,cmLoadPCX2,
  1356.       NewStatusKey ('',kbCtrlF2,cmSaveConfig,
  1357.       NewStatusKey ('',kbCtrlF3,cmLoadConfig,
  1358.       NewStatusKey ('',kbCtrlF5,cmResize,
  1359.       NewStatusKey ('',kbF10,cmMenu,
  1360.       nil)))))))))),nil)))
  1361. end;
  1362.  
  1363. {
  1364. Message when safety pool is cut into.
  1365. }
  1366.  
  1367. procedure TCyberAni.OutOfMemory;
  1368.  
  1369. begin
  1370.   MessageBox (#3'Not enough memory available to complete operation.  Try closing some windows!',
  1371.   nil,mfError+mfOkButton)
  1372. end;
  1373.  
  1374. {
  1375. Load desk top from stream.
  1376. }
  1377.  
  1378. procedure TCyberAni.LoadDesktop (var S : TStream);
  1379.  
  1380. var
  1381.  
  1382.   Pal : PString;
  1383.  
  1384. begin
  1385.   Pal := S.ReadStr;
  1386.   if Pal <> nil then
  1387.   begin
  1388.     Application^.GetPalette^ := Pal^;
  1389.     DoneMemory;
  1390.     DisposeStr (Pal)
  1391.   end
  1392. end;
  1393.  
  1394. {
  1395. Store desk top on stream.
  1396. }
  1397.  
  1398. procedure TCyberAni.StoreDesktop(var S: TStream);
  1399.  
  1400. var
  1401.  
  1402.   Pal: PString;
  1403.  
  1404. begin
  1405.   Pal := @Application^.GetPalette^;
  1406.   S.WriteStr (Pal)
  1407. end;
  1408.  
  1409. {
  1410. If VGA is present then start TV app else print error message.
  1411. }
  1412.  
  1413. var
  1414.  
  1415.   CFApp : TCyberAni;
  1416.  
  1417. begin
  1418.   if VGACardActive then
  1419.   begin
  1420.     CFApp.Init;
  1421.     SysErrorFunc := AppSystemError;
  1422.     CFApp.Run;
  1423.     CFApp.Done
  1424.   end
  1425.   else
  1426.     PrintStr (#13#10'VGA display required to run CyberAnimate!'#13#10);
  1427. end.
  1428.